﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace Jemgine.Data
{
    public class VertexTranslateTag
    {
        public HasVerticies Owner;
        internal Vector2 Position;
    }

    public class Vertex : Translatable, IVertex
    {
        public Vector2 Position { get; set; }

        public Vertex(Vector2 Position)
        {
            this.Position = Position;
        }

        public Vertex() { }

        #region Translatable Members

        object Translatable.PrepareToTranslate()
        {
            return new VertexTranslateTag { Position = Position };
        }

        void Translatable.ApplyTranslation(object Tag, Vector2 MouseDelta)
        {
            VertexTranslateTag _Tag = Tag as VertexTranslateTag;
            Vector2 OriginalPosition = _Tag.Position;
            Position = OriginalPosition + MouseDelta;
            if (_Tag.Owner != null) _Tag.Owner.ClearDecomposedCache();
        }

        void Translatable.Snap(Snapper Snapper)
        {
            Position = Snapper.SnapPosition(Position);
        }

        #endregion
    }

    public interface IVertex
    {
        Vector2 Position { get; set; }
    }

    public interface HasVerticies
    {
        int Count { get; }
        IVertex GetVertex(int Index);
        void ClearDecomposedCache();
    }
}